﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using DTO;
using System.Data;

namespace DAO
{
    public class daoThucPham
    {
        public static DataTable LoadThucPham()
        {
            return DataProvider.SpSelect("usp_LoadThucPham");
        }

        public static DataTable LoadGiaTheoMa(dtoThucPham thucpham)
        {
            string proc_name = "usp_LoadGiaTheoThucPham";
            var parameters = new List<SqlParameter>
                                 {
                                     new SqlParameter("@ma ", thucpham.Ma_TP){ SqlDbType = SqlDbType.Int },                                    
                                 };
          
            return (DataTable)DataProvider.SpSelectTheoThamSo(proc_name, parameters);
        }
        public static int AddThucPham(dtoThucPham thucpham)
        {
            var parameters = new List<SqlParameter>
                                 {
                                     new SqlParameter("@TenTP ", thucpham.Ten_TP){SqlDbType = SqlDbType.NVarChar},
                                     new SqlParameter("@SoLuong", thucpham.SoLuong){SqlDbType = SqlDbType.Float},
                                     new SqlParameter("@DonGia ", thucpham.DonGia){SqlDbType = SqlDbType.Int},
                                     new SqlParameter("@HSD", thucpham.HSD){SqlDbType = SqlDbType.SmallDateTime},
                                     new SqlParameter("@NCC ", thucpham.Ma_NCC){SqlDbType = SqlDbType.SmallInt},
                                     new SqlParameter("@DViTinh", thucpham.Ma_DViTinh){SqlDbType = SqlDbType.SmallInt},
                                 };
            var output = new SqlParameter("@Ma_TP", SqlDbType.Int) { Direction = ParameterDirection.Output };
            return (int)DataProvider.spInsert_Update_Test("usp_ThemThucPham", parameters, output);

        }

    }
}
